home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Alpha Blending Lines and Fills / Setting the Alpha Values of Individual Pixels / GDITEST2.dpr
Encoding:
Text File  |  2003-10-15  |  2.9 KB  |  117 lines

  1. program GDITEST2;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   Width, Height, Row, Column: Integer;
  14.   color, colorTemp: TGPColor;
  15.   Pen: TGPPen;
  16.   bitmap: TGPBitmap;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.  
  20.   Bitmap := TGPBitmap.Create('..\..\Media\Texture1.jpg');
  21.  
  22.   Width  := bitmap.GetWidth;
  23.   Height := bitmap.GetHeight;
  24.  
  25.   for Row := 0 to Height - 1 do
  26.   begin
  27.     for Column := 0 to Width - 1 do
  28.     begin
  29.       bitmap.GetPixel(Column, Row, color);
  30.       colorTemp := MakeColor(
  31.            (255 * Column div Width),
  32.            GetRed(color),
  33.            GetGreen(color),
  34.            GetBlue(color));
  35.       bitmap.SetPixel(Column, Row, colorTemp);
  36.     end;
  37.   end;
  38.  
  39.   // First draw a wide black line.
  40.   Pen := TGPPen.Create(MakeColor(255, 0, 0, 0), 25);
  41.   graphics.DrawLine(pen, 10, 35, 200, 35);
  42.  
  43.   // Now draw the modified bitmap.
  44.   graphics.DrawImage(bitmap, 30, 0, Width, Height);
  45.  
  46.   Bitmap.Free;
  47.   Pen.Free;
  48.   graphics.Free;
  49. end;
  50.  
  51.  
  52. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  53. var
  54.   Handle: HDC;
  55.   ps: PAINTSTRUCT;
  56. begin
  57.   case message of
  58.     WM_PAINT:
  59.       begin
  60.         Handle := BeginPaint(Wnd, ps);
  61.         OnPaint(Handle);
  62.         EndPaint(Wnd, ps);
  63.         result := 0;
  64.       end;
  65.  
  66.     WM_DESTROY:
  67.       begin
  68.         PostQuitMessage(0);
  69.         result := 0;
  70.       end;
  71.  
  72.    else
  73.       result := DefWindowProc(Wnd, message, wParam, lParam);
  74.    end;
  75. end;
  76.  
  77. var
  78.   hWnd     : THandle;
  79.   Msg      : TMsg;
  80.   wndClass : TWndClass;
  81. begin
  82.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  83.    wndClass.lpfnWndProc    := @WndProc;
  84.    wndClass.cbClsExtra     := 0;
  85.    wndClass.cbWndExtra     := 0;
  86.    wndClass.hInstance      := hInstance;
  87.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  88.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  89.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  90.    wndClass.lpszMenuName   := nil;
  91.    wndClass.lpszClassName  := 'GettingStarted';
  92.  
  93.    RegisterClass(wndClass);
  94.  
  95.    hWnd := CreateWindow(
  96.       'GettingStarted',       // window class name
  97.       'Setting the Alpha Values of Individual Pixels',       // window caption
  98.       WS_OVERLAPPEDWINDOW,    // window style
  99.       Integer(CW_USEDEFAULT), // initial x position
  100.       Integer(CW_USEDEFAULT), // initial y position
  101.       Integer(CW_USEDEFAULT), // initial x size
  102.       Integer(CW_USEDEFAULT), // initial y size
  103.       0,                      // parent window handle
  104.       0,                      // window menu handle
  105.       hInstance,              // program instance handle
  106.       nil);                   // creation parameters
  107.  
  108.    ShowWindow(hWnd, SW_SHOW);
  109.    UpdateWindow(hWnd);
  110.  
  111.    while(GetMessage(msg, 0, 0, 0)) do
  112.    begin
  113.       TranslateMessage(msg);
  114.       DispatchMessage(msg);
  115.    end;
  116. end.
  117.